//
//  ViewController.m
//  SmoothNavDemo
//
//  Created by Cloudox on 2017/3/15.
//  Copyright © 2017年 Cloudox. All rights reserved.
//

#import "WhiteNavController.h"
#import "AlphaViewController.h"
#import "HiddenNavController.h"
#import "NormalDarkController.h"

#import "UINavigationController+Cloudox.h"
#import "UIViewController+Cloudox.h"
#import <Masonry.h>

@interface WhiteNavController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong ,nonatomic) UITableView *myTable;
@end

@implementation WhiteNavController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = @"WhiteNormalNav";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myTable];

    self.navigationController.navigationBarHidden = YES;
    [self updateViewConstraints];
//    self.myTable.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"nav_msg"] style:UIBarButtonItemStylePlain target:self action:@selector(goBlueNormalNav)];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"nav_download"] style:UIBarButtonItemStylePlain target:self action:@selector(goAlphaNav)];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    self.navigationController.navigationBar.barTintColor = nil;
//    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
//    self.navBarBgAlpha = @"1.0";
//    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor]};
}

- (void)updateViewConstraints
{
    [super updateViewConstraints];
    [self.myTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(self.view);
    }];
}

#pragma mark - Methods
// 获取子视图
- (void)getSub:(UIView *)view andLevel:(int)level
{
    NSArray *subviews = [view subviews];
    if ([subviews count] == 0) return;
    for (UIView *subview in subviews)
    {
        NSString *blank = @"";
        for (int i = 1; i < level; i++)
        {
            blank = [NSString stringWithFormat:@"  %@", blank];
        }
        NSLog(@"%@%d: %@", blank, level, subview.class);
        [self getSub:subview andLevel:(level+1)];
        
    }
}

#pragma mark - Methods

#pragma mark - Action
- (void)goAlphaNav
{
    AlphaViewController *controller = [[AlphaViewController alloc] init];
    controller.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:controller animated:YES];
}

- (void)goBlueNormalNav
{
    NormalDarkController *controller = [[NormalDarkController alloc] init];
    controller.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:controller animated:YES];
}

- (void)goWhiteNormalNav
{
    WhiteNavController *controller = [[WhiteNavController alloc] init];
    controller.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:controller animated:YES];
}

- (void)goHiddenNav
{
    HiddenNavController *controller = [[HiddenNavController alloc] init];
    controller.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:controller animated:YES];
}

#pragma mark - Getter
- (UITableView *)myTable
{
    if (_myTable == nil)
    {
        _myTable = [[UITableView alloc] init];
        _myTable.backgroundColor = [UIColor clearColor];
        _myTable.dataSource = self;
        _myTable.delegate = self;
    }
    return _myTable;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 15;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WhiteNavCell"];
    cell.backgroundColor = [UIColor colorWithRed:0.165 green:0.804 blue:0.804 alpha:1.000];
    cell.textLabel.textColor = [UIColor whiteColor];
    switch (indexPath.row)
    {
        case 0:
        {
            cell.textLabel.text = @"goWhiteNormalNav";
            break;
        }
        case 1:
        {
            cell.textLabel.text = @"goBlueNormalNav";
            break;
        }
        case 2:
        {
            cell.textLabel.text = @"goHiddenNav";
            break;
        }
        case 3:
        {
            cell.textLabel.text = @"goAlphaNav";
            break;
        }
        default:
            break;
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row)
    {
        case 0:
        {
            [self goWhiteNormalNav];
            break;
        }
        case 1:
        {
            [self goBlueNormalNav];
            break;
        }
        case 2:
        {
            [self goHiddenNav];
            break;
        }
        case 3:
        {
            [self goAlphaNav];
            break;
        }
        default:
            break;
    }
}
@end
